/* webpack.config_prod.js */
var path = require('path');
var webpack = require('webpack');
var webpackMerge = require('webpack-merge');
var webpackConfig = require('./webpack.config.js');
var CleanWebpack = require('clean-webpack-plugin').CleanWebpackPlugin;
var OptimizeCssAssetsPlugin = require("optimize-css-assets-webpack-plugin");
 
// 清空基本配置的插件列表
// webpackConfig.plugins = [];
 
module.exports = webpackMerge(webpackConfig, {
    mode: 'production',     // 定义当前为生产环境
    plugins: [
        new CleanWebpack(),
        new OptimizeCssAssetsPlugin({
            assetNameRegExp: /\.css$/g,
            cssProcessor: require("cssnano"),
            cssProcessorPluginOptions:{
                preset: ['default', {
                    discardComments: {removeAll: true}
                }]
            },
            canPrint:true
        })
    ],
    // 对js文件进行压缩
    optimization: {
        runtimeChunk: true,
        splitChunks:{
            chunks: 'all',
            minSize: 20000,
            cacheGroups:{
                mudules: {
                    test: /[\\/]node_modules[\\/]/,
                    minSize: 30000,
                    minChunks: 1,
                    chunks: 'initial',
                    priority: -10
                },
                common: {
                    test: /[\\/]src[\\/]common[\\/]/,
                    name: 'commons',
                    minSize: 9000,
                    minChunks: 3,
                    chunks: 'initial',
                    priority: -4,
                    reuseExistingChunk: true
                },
                default: {
                    minChunks: 2,
                    priority: -20,   // 优先级配置项
                    reuseExistingChunk: true
                }
            }
        }
    }
});
